-----------------------------------
-- Area: Windurst Waters
-- NPC:  Piketo-Puketo
-- Type: Cooking Guild Master
-- @zone 238
-- @pos -124.012 -2.999 59.998
-----------------------------------
package.loaded["scripts/zones/Windurst_Waters/TextIDs"] = nil;
-----------------------------------

require("scripts/globals/crafting");
require("scripts/zones/Windurst_Waters/TextIDs");

local SKILLID = 56; -- Cooking

-----------------------------------
-- onTrade Action
-----------------------------------

function onTrade(player,npc,trade)
	local newRank = tradeTestItem(player,npc,trade,SKILLID);

	if(newRank ~= 0) then
		player:setSkillRank(SKILLID,newRank);
		player:startEvent(0x271e,0,0,0,0,newRank);
	end

end;

-----------------------------------
-- onTrigger Action
-----------------------------------

function onTrigger(player,npc)
	local getNewRank = 0;
	local craftSkill = player:getSkillLevel(SKILLID);
	local testItem = getTestItem(player,npc,SKILLID);
	local guildMember = isGuildMember(player,4);

	if(guildMember == 1) then
		guildMember = 150995375;
	end
	if(canGetNewRank(player,craftSkill,SKILLID) == 1) then
		getNewRank = 100;
	end

	player:startEvent(0x271d,testItem,getNewRank,30,guildMember,44,0,0,0);

end;

-- 0x03d2  0x03d7  0x03d4  0x03d5  0x271d  0x271e

-----------------------------------
-- onEventUpdate
-----------------------------------

function onEventUpdate(player,csid,option)
	-- printf("CSID: %u",csid);
	-- printf("RESULT: %u",option);
end;

-----------------------------------
-- onEventFinish
-----------------------------------

function onEventFinish(player,csid,option)
	-- printf("CSID: %u",csid);
	-- printf("RESULT: %u",option);

	if(csid == 0x271d and option == 1) then	
		local crystal = math.random(4096,4101);

		if(player:getFreeSlotsCount() == 0) then 
			player:messageSpecial(ITEM_CANNOT_BE_OBTAINED,crystal);
		else
			player:addItem(crystal);
			player:messageSpecial(ITEM_OBTAINED,crystal);
			signupGuild(player,16);
		end
	end

end;